from pydantic import BaseModel, Field, validator
from typing import Optional
import re


class DraftAddImageRequest(BaseModel):
    """添加图片到草稿请求模型"""
    # 核心参数
    image_url: str = Field(..., description="图片链接")
    draft_folder: Optional[str] = Field(None, description="草稿文件夹路径")
    width: int = Field(1080, description="目标视频画布的宽度")
    height: int = Field(1920, description="目标视频画布的高度")
    start: float = Field(0, description="在目标轨道上的开始时间，单位秒")
    end: float = Field(3.0, description="在目标轨道上的结束时间，单位秒，默认3秒")
    draft_id: Optional[str] = Field(None, description="目标草稿的草稿id")
    # 变换参数
    transform_y: float = Field(0, description="垂直移动单位距离，0表示位于中心")
    scale_x: float = Field(1, description="水平方向缩放")
    scale_y: float = Field(1, description="垂直方向缩放")
    transform_x: float = Field(0, description="水平移动单位距离，0表示位于中心")
    # 轨道参数
    track_name: str = Field("main", description="添加的轨道名称")
    relative_index: int = Field(0, description="轨道相对位置，越大越靠前")
    # 动画参数
    animation: Optional[str] = Field(None, description="入场动画参数（向后兼容）")
    animation_duration: float = Field(0.5, description="入场动画持续时间参数，默认0.5秒")
    intro_animation: Optional[str] =Field( None, description = "新入场动画参数，优先级高于animation")
    intro_animation_duration: float = Field(0.5, description="新入场动画持续时间参数，默认0.5秒")
    outro_animation: Optional[str] = Field(None, description="出场动画参数")
    outro_animation_duration: float = Field(0.5, description="出场动画持续时间参数，默认0.5秒")
    combo_animation: Optional[str] = Field(None, description="组合动画参数")
    combo_animation_duration: float = Field(0.5, description="组合动画持续时间参数，默认0.5秒")
    # 转场参数
    transition: Optional[str] = Field(None, description="转场类型参数")
    transition_duration: float = Field(0.5, description="转场持续时间参数（秒），默认0.5秒")
    # 蒙版相关参数
    mask_type: Optional[str] = Field(None, description="蒙版类型：Linear, Mirror, Circle, Rectangle, Heart, Star")
    mask_center_x: float = Field(0.0, description="蒙版中心X坐标")
    mask_center_y: float = Field(0.0, description="蒙版中心Y坐标")
    mask_size: float = Field(0.5, description="蒙版主大小")
    mask_rotation: float = Field(0.0, description="蒙版旋转角度")
    mask_feather: float = Field(0.0, description="蒙版羽化参数（0-100）")
    mask_invert: bool = Field(False, description="是否反转蒙版")
    mask_rect_width: Optional[float] = Field(None, description="矩形蒙版宽度（仅矩形蒙版）")
    mask_round_corner: Optional[float] = Field(None, description="矩形蒙版圆角（仅矩形蒙版，0-100）")
    # 背景参数
    background_blur: Optional[int] = Field(None, description="背景模糊级别，1-4，对应四个模糊强度等级")
